from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from time import sleep


class Base:
    def __init__(self, driver):
        self.driver = driver

    def open_url(self, url):
        self.driver.get(url)

    # 显示等待方法
    def find_selent(self, loc):
        WebDriverWait(self.driver, 20, 0.5).until(EC.visibility_of_element_located(loc))
        return self.driver.find_element(*loc)

    # 点击
    def click(self, loc):
        self.find_selent(loc).click()

    # 输入
    def send_keys(self, loc, txt):
        self.find_selent(loc).send_keys(txt)

    # 切换句柄
    def new_switch(self):
        self.driver.switch_to(self.driver.window_handles[-1])

    # 强制等待方法
    def waitsp(self, n):
        sleep(n)

    # 隐式等待方法
    def imlewait(self, n):
        self.driver.implicitly_wait(n)
